package com.lazybones.base.engineer.utils.meun;

import com.lazybones.base.engineer.common.menus.ITreeNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;

public class TreeNodeUtils {
    private static final Logger log = LoggerFactory.getLogger(TreeNodeUtils.class);
    public static final String PARENT_NAME="parent";
    public static final String CHILDREN_NAME="childrenName";
    public static final List<Object> IDS = Collections.singletonList(0L);
    public static  <T extends ITreeNode<T>> List<T> buildTree(List<T> dataList){
        return  buildTree(dataList,IDS,(data)->data,(itme) ->true);
    }
    public static <T extends ITreeNode<T>> List<T> buildTree(List<T> dataList, Function<T,T> map){
        return buildTree(dataList,IDS,map,(item)->true);
    }
    public static <T extends ITreeNode<T>> List<T> buildTree(List<T> dataList, Function<T,T> map, Predicate<T> filter){
        return buildTree(dataList,IDS,map,filter);
    }
    public static<T extends ITreeNode<T>> List<T> buildTree(List<T> dataList,List<Object> ids){
        return buildTree(dataList,ids,(data)->data,(item) ->true);
    }
    public static <T extends ITreeNode<T>> List<T> buildTree(List<T> dataList,List<Object> ids,Function<T,T> map){
        return buildTree(dataList,ids,map,(item)->true);
    }
    public static <T extends ITreeNode<T>> List<T> buildTree(List<T> dataList,List<Object> ids,Function<T,T> map,Predicate<T> filter){
        if(CollectionUtils.isEmpty(ids)){
            return Collections.emptyList();
        }
//        Map<String,List<T>> nodeMap = dataList.stream().flatMap(filter).collect(Collectors.groupingBy(item -> ids.contains(item.)));
        return null;
    }

}
